package com.ey12.db.dao;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.ey12.db.domain.GmUserfinance;

/**
 * Data access object (DAO) for domain model class GmUserfinance.
 * 
 * @see com.ey12.db.domain.GmUserfinance
 * @author MyEclipse Persistence Tools
 */

public class GmUserfinanceDAO extends HibernateDaoSupport {
	private static final Log log = LogFactory.getLog(GmUserfinanceDAO.class);
	// property constants
	public static final String FILL_MONEY = "fillMoney";
	public static final String HAVE_MONEY = "haveMoney";
	public static final String GET_MONEY = "getMoney";
	public static final String USED_MONEY = "usedMoney";
	public static final String TO_BANK_MONEY = "toBankMoney";

	protected void initDao() {
		// do nothing
	}

	public void saveOrUpdate(GmUserfinance transientInstance) {
		log.debug("saving GmUserfinance instance");
		try {
			getHibernateTemplate().saveOrUpdate(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(GmUserfinance persistentInstance) {
		log.debug("deleting GmUserfinance instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public GmUserfinance findById(java.lang.Integer id) {
		log.debug("getting GmUserfinance instance with id: " + id);
		try {
			GmUserfinance instance = (GmUserfinance) getHibernateTemplate()
					.get("com.ey12.db.domain.GmUserfinance", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(GmUserfinance instance) {
		log.debug("finding GmUserfinance instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding GmUserfinance instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from GmUserfinance as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByFillMoney(Object fillMoney) {
		return findByProperty(FILL_MONEY, fillMoney);
	}

	public List findByHaveMoney(Object haveMoney) {
		return findByProperty(HAVE_MONEY, haveMoney);
	}

	public List findByGetMoney(Object getMoney) {
		return findByProperty(GET_MONEY, getMoney);
	}

	public List findByUsedMoney(Object usedMoney) {
		return findByProperty(USED_MONEY, usedMoney);
	}

	public List findByToBankMoney(Object toBankMoney) {
		return findByProperty(TO_BANK_MONEY, toBankMoney);
	}

	public List findAll() {
		log.debug("finding all GmUserfinance instances");
		try {
			String queryString = "from GmUserfinance";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public GmUserfinance merge(GmUserfinance detachedInstance) {
		log.debug("merging GmUserfinance instance");
		try {
			GmUserfinance result = (GmUserfinance) getHibernateTemplate()
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(GmUserfinance instance) {
		log.debug("attaching dirty GmUserfinance instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(GmUserfinance instance) {
		log.debug("attaching clean GmUserfinance instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static GmUserfinanceDAO getFromApplicationContext(
			ApplicationContext ctx) {
		return (GmUserfinanceDAO) ctx.getBean("GmUserfinanceDAO");
	}
}